#!/usr/bin/python
# -*- coding: UTF-8 -*-

from MiniBotControlLib import MiniBotControlLib
from SpiderModuleRobot import *
import time,threading
# import ipdb

class SpiderModuleRobot:
	TIME=0.3 #前进、后退左右转
	TIMES=0.9 #打招呼、做运动、跳舞、蹲下起立
	FaceFlag = 0 ##变脸标志位
	Threading = 0 ##多线程标志位
	threading_1 = 0
	threading_2 = 0
########协议传感器开关#######
	SensorOn = [1]
	SensorOff = [0]

########速度#######
	# SPEED = 30##高配版
	SPEED = 5##低配版
	SPEED2 = [SPEED,SPEED]
	SPEED4 = [SPEED,SPEED,SPEED,SPEED]
	SPEED6 = [SPEED,SPEED,SPEED,SPEED,SPEED,SPEED]
	SPEED8 = [SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED]
	SPEED12 = [SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED,SPEED]


########向左直走########
	LeftMoveOutStep  = -40 #向左直走往外跨步
	LeftMoveInStep  = -90 #向左直走往内跨步
	LeftMoveInitStep = -80 #原始状态
	LeftMoveInitSmallStep = -50 #右脚移动

########向右直走########
	RightMoveOutStep =  -40 #向右直走往外跨步
	RightMoveInStep =  -90 #向右直走往内跨步
	RightMoveInitStep = -80 #原始状态
	RightMoveInitSmallStep = -50 #左脚移动

########自转角度########
	OriStep = 90
	TurnAngle = 30
	TurnUpAngle = 40

########蹲下站立########
	Stand = 80
	Down = 20

########打招呼########
	FrontLeg = 45
	MiddleLeg = 30
	BackLeg = 0
	FrontHand = 0
	MiddleHand = 80
	BackHand = 20
	HandRangeHigh = 20
	HandRangeLow = 20
	LegRangeHigh = 45
	LegRangeLow = 25
	LegRangeHighFour = 50
	LegRangeLowFour = 0
	leg03 = [28,29,34,35]
	leg25 = [32,33,38,39]

########俯卧撑########
	SportUp = -80
	SportDown = -30
	leg0134 = [ 29,31,35,37 ]

########跳舞########
	DanceUp = -90
	DanceDown = -35
	leg01 = [ 29,31 ]
	leg25 = [ 33,39 ]
	leg34 = [ 35,37 ]
	leg_dance = [ 29,31 ,33,39,35,37 ]
	leg_danceFour = [29,33,39,35]
	leg_RArmFour = [34,35]

########同时控制一条腿########
	leg0 = [ 28,29 ]
	leg1 = [ 30,31]
	leg2 = [ 32,33 ]
	leg3 = [ 34,35 ]
	leg4 = [ 36,37 ]
	leg5 = [ 38,39]

########同时控制两条腿########
	leg05 = [ 28,29,38,39 ]
	leg23 = [ 32,33,34,35]
	leg0235 = [ 28,29,32,33,34,35,38,39 ]

########同时控制三条腿########
	leg0_2_4 = [ 28,29,32,33,36,37 ]
	leg1_3_5 = [ 30,31,34,35,38,39 ]

########同时控制六条腿########
	leg_all = [ 28,29,30,31,32,33,34,35,36,37,38,39 ]
	leg_LRArm = [ 28,30,32,34,36,38 ]#六腿左右摆动臂
	leg_UDArm = [ 29,31,33,35,37,39 ]#六腿上下摆动臂


########TTT4腿蜘蛛########
	Tleg1 = [28,29,30]#1腿
	Tleg2 = [ 31,32,33 ]#2腿
	Tleg3 = [ 34,35,36 ]#3腿
	Tleg4 = [ 37,38,39 ]#4腿
	Tleg14 = [ 28,29,30,37,38,39 ]#14腿
	Tleg23 = [ 31,32,33, 34,35,36 ]#23腿

########################初始化位置########################
	Step_init = [ 0 , -90 , 0 , -90 ,0 , -90 ]
	# Step_init135 = [ 0 , -ReStepDown , 0 , -ReStepDown ,-30 , -ReStepDown ]
	# Step_init024 = [ 0 , -ReStepDown , 30 , -ReStepDown ,0 , -ReStepDown ]
	# Step_init135B = [ 0 , -ReStepDown , 30 , -ReStepDown ,0 , -ReStepDown ]
	# Step_init024B = [ -30 , -ReStepDown , 0 , -ReStepDown,0 , -ReStepDown ]



########################前进步态########################
		##TT6腿蜘蛛##
##初始状态为第一个关节均为0度
	ForwardAngleL = 20
	ForwardAngleR  = 20
	ForwardInit = 0
	ReStepUp = 35
	ReStepDown = 60
	StepForward_UpFirst = [- ForwardInit,-ReStepUp,-ForwardInit,-ReStepUp ,ForwardInit,-ReStepUp ]#First 为L1 L3 R2  ;Second为L2 R1 R3  所有角度原始为0度
	StepForward_ForwardFirst = [ -10,-ReStepUp,-ForwardAngleL,-ReStepUp ,ForwardAngleL,-ReStepUp ]#第一组腿向前且抬起腿
	StepForward_DownFirst = [ -10,-ReStepDown,-ForwardAngleL,-ReStepDown ,ForwardAngleL,-ReStepDown ]#第一组放下腿
	StepForward_UpSecond = [ForwardInit,-ReStepUp,-ForwardInit,-ReStepUp ,-ForwardInit,-ReStepUp ]#First 为LI L3 R2  ;Second为L2 R1 R3
	StepForward_ForwardSecond = [ -ForwardAngleR,-ReStepUp,ForwardAngleR,-ReStepUp ,ForwardAngleR,-ReStepUp ]#第二组腿向前且抬起腿
	StepForward_DownSecond = [ -ForwardAngleR,-ReStepDown,ForwardAngleR,-ReStepDown ,ForwardAngleR,-ReStepDown ]#第二组放下腿
	StepForward_024Re135Forward = [ -ForwardInit,-ForwardAngleR,-ForwardInit,ForwardAngleR,ForwardInit,ForwardAngleR ]#024恢复135向前
	StepForward_135Re024Forward = [-10,ForwardInit,-ForwardAngleL,-ForwardInit,ForwardAngleL,-ForwardInit ]#135恢复024向前


########TTT6腿蜘蛛前进########
##初始状态为第一个关节均为0度
	# ForwardAngleL = 20
	# ForwardAngleR  = 20
	# ForwardInit = 0
	# ReStepUp = 60
	# ReStepDown = 20
	# StepForward_UpFirst = [ -ForwardInit,ReStepUp,-ForwardInit,ReStepUp ,ForwardInit,ReStepUp ]#First 为L1 L3 R2  ;Second为L2 R1 R3  所有角度原始为0度
	# StepForward_ForwardFirst = [ -12,ReStepUp,-ForwardAngleL,ReStepUp ,ForwardAngleL,ReStepUp ]
	# StepForward_DownFirst = [ -12,ReStepDown,-ForwardAngleL,ReStepDown ,ForwardAngleL,ReStepDown ]
	# StepForward_UpSecond = [ ForwardInit,ReStepUp,-ForwardInit,ReStepUp ,-ForwardInit,ReStepUp ]#First 为LI L3 R2  ;Second为L2 R1 R3
	# StepForward_ForwardSecond = [ -ForwardAngleR,ReStepUp,ForwardAngleR,ReStepUp ,ForwardAngleR,ReStepUp ]
	# StepForward_DownSecond = [ -ForwardAngleR,ReStepDown,ForwardAngleR,ReStepDown ,ForwardAngleR,ReStepDown ]
	# StepForward_024Re135Forward = [ -ForwardInit,-ForwardAngleR,-ForwardInit,ForwardAngleR,ForwardInit,ForwardAngleR ]
	# StepForward_135Re024Forward = [ -12,ForwardInit,-ForwardAngleL,-ForwardInit,ForwardAngleL,-ForwardInit ]

########TT4腿蜘蛛前进########
	FourStepUp = 50
	FourStepTurn = 30
	FourStepDown = 90
	FourForwardUp = [0,-FourStepUp,0,-FourStepUp ]
	FourForwardDown = [ -FourStepTurn,-FourStepDown,FourStepTurn,-FourStepDown ]
	FourForwardInit = [ 0,-FourStepDown,0,-FourStepDown ]
	FourForward05Re23Forward = [0,-FourStepDown , -FourStepTurn,-FourStepUp,  FourStepTurn,-FourStepUp,  0,-FourStepDown ]#05腿恢复，23腿转
	FourForward23Re05Forward = [ -FourStepTurn,-FourStepUp ,  0,-FourStepDown,  0,-FourStepDown, FourStepTurn,-FourStepUp ]#23恢复，05转
##匍匐前进
	DownFourStepUp = 10
	DownFourStepTurn = 30
	DownFourStepDown = 30
	DownFourForwardUp = [0,-DownFourStepUp,0,-DownFourStepUp ]
	DownFourForwardDown = [ -DownFourStepTurn,-DownFourStepDown,DownFourStepTurn,-DownFourStepDown ]
	DownFourForwardInit = [ 0,-DownFourStepDown,0,-DownFourStepDown ]
	DownFourForward05Re23Forward = [0,-DownFourStepDown , -DownFourStepTurn,-DownFourStepUp,  DownFourStepTurn,-DownFourStepUp,  0,-DownFourStepDown ]#05腿恢复，23腿转
	DownFourForward23Re05Forward = [ -DownFourStepTurn,-DownFourStepUp ,  0,-DownFourStepDown,  0,-DownFourStepDown, DownFourStepTurn,-DownFourStepUp ]#23恢复，05转

########四足小狗前进########
	FourDogUp = 50
	FourDogTurn = 45
	FourDogDown = 90
	FourDog_InitF  = [-FourDogTurn,-80, FourDogTurn ,-90,FourDogTurn,-80, -FourDogTurn,-90 ]
	FourDog_UpF = [ FourDogTurn, -FourDogUp, FourDogTurn, -FourDogUp ]
	FourDog8Leg1F = [ -FourDogTurn,-FourDogDown, FourDogTurn ,-FourDogUp,FourDogTurn, -FourDogUp, -FourDogTurn,-FourDogDown ]#05腿恢复，23抬
	FourDog8Leg2F = [ -FourDogTurn,-FourDogUp, FourDogTurn ,- FourDogDown,FourDogTurn, -FourDogDown, -FourDogTurn,-FourDogUp ]#23恢复，05抬


########################后退步态########################
########TTT6腿蜘蛛后退########
##初始状态为第一个关节均为0度
	StepBack_UpFirst = [ -ForwardInit, -ReStepUp, -ForwardInit, -ReStepUp, ForwardInit, -ReStepUp ]#First 为LI L3 R2  ;Second为L2 R1 R3
	StepBack_BackFirst = [ 15,-ReStepUp,ForwardAngleL,-ReStepUp ,-ForwardAngleL,-ReStepUp ]
	StepBack_DownFirst = [ 15,-ReStepDown,ForwardAngleL,-ReStepDown ,-ForwardAngleL,-ReStepDown ]
	StepBack_UpSecond = [ ForwardInit, -ReStepUp, -ForwardInit, -ReStepUp, -ForwardInit, -ReStepUp ]#First 为LI L3 R2  ;Second为L2 R1 R3
	StepBack_BackSecond = [ ForwardAngleR,-ReStepUp,-ForwardAngleR,-ReStepUp ,-ForwardAngleR,-ReStepUp ]
	StepBack_DownSecond = [ ForwardAngleR,-ReStepDown,-ForwardAngleR,-ReStepDown ,-ForwardAngleR,-ReStepDown ]
	StepBack_024Re135Back = [ ForwardInit,ForwardAngleR,ForwardInit,-ForwardAngleR,ForwardInit,-ForwardAngleR ]
	StepBack_135Re024Back = [ 20,ForwardInit,ForwardAngleL,ForwardInit,-ForwardAngleL,ForwardInit ]

########四足小狗后退########
	FourDog_InitB = [ -FourDogTurn,-90, FourDogTurn ,-,FourDogTurn,-90, -FourDogTurn,-80 ]
	FourDog_UpB = [  -FourDogTurn, -FourDogUp, -FourDogTurn, -FourDogUp ]
	FourDog8Leg2B = [ -FourDogTurn,-FourDogDown, FourDogTurn ,-FourDogUp,FourDogTurn, -FourDogUp, -FourDogTurn,-FourDogDown ]#05腿恢复，23抬
	FourDog8Leg1B = [ -FourDogTurn,-FourDogUp, FourDogTurn ,-FourDogDown,FourDogTurn, -FourDogDown, -FourDogTurn,-FourDogUp ]#23恢复，05抬

########TT4腿蜘蛛后退########
	FourBackUp = [ 0,-FourStepUp,0,-FourStepUp ]
	FourBackDown = [ FourStepTurn,-FourStepDown,-FourStepTurn,-FourStepDown ]
	FourBackInit = [ 0,-FourStepDown,0,-FourStepDown ]
	FourBack05Re23Back = [ 0,-FourStepDown ,  FourStepTurn,-FourStepUp,  -FourStepTurn,-FourStepUp,  0,-FourStepDown ]#05腿恢复，23腿转
	FourBack23Re05Back = [ FourStepTurn,-FourStepUp ,  0,-FourStepDown,  0,-FourStepDown, -FourStepTurn,-FourStepUp ]#23恢复，05转

########TT4腿蜘蛛匍匐后退########
	DownFourBackUp = [ 0,-DownFourStepUp,0,-DownFourStepUp ]
	DownFourBackDown = [ DownFourStepTurn,-DownFourStepDown,-DownFourStepTurn,-DownFourStepDown ]
	DownFourBackInit = [ 0,-DownFourStepDown,0,-DownFourStepDown ]
	DownFourBack05Re23Back = [ 0,-DownFourStepDown ,  DownFourStepTurn,-DownFourStepUp,  -DownFourStepTurn,-DownFourStepUp,  0,-DownFourStepDown ]#05腿恢复，23腿转
	DownFourBack23Re05Back = [ DownFourStepTurn,-DownFourStepUp ,  0,-DownFourStepDown,  0,-DownFourStepDown, -DownFourStepTurn,-DownFourStepUp ]#23恢复，05转

########################向左步态########################
########TTT6腿蜘蛛向左直走########
	Step_LeftMoveInit = [ 0,LeftMoveInitStep,0,LeftMoveInitStep,0,LeftMoveInitStep,0,LeftMoveInitStep,0,LeftMoveInitStep,0,LeftMoveInitStep ]
	Step_LeftMoveFirst = [ 0,LeftMoveOutStep, 0,LeftMoveInStep,  0,LeftMoveOutStep,  0,LeftMoveInitSmallStep,  0,LeftMoveInStep,  0,LeftMoveInitSmallStep]
	Step_LeftMoveSecond = [ 0,LeftMoveOutStep, 0,-30,  0,LeftMoveOutStep,  0,LeftMoveInitSmallStep,  0,-30,  0,LeftMoveInitSmallStep ]
	Step_LeftMoveThird = [ 0,LeftMoveInitStep, 0,-30,  0,LeftMoveInitStep,  0,LeftMoveInitStep,  0,-30,  0,LeftMoveInitStep ]

########TTT6腿蜘蛛自转步态向左########
	TurnLeft_Up = [ 0,-TurnUpAngle,0,-TurnUpAngle ,0,-TurnUpAngle ]
	TurnLeft_Turn = [ TurnAngle,-TurnUpAngle,TurnAngle,-TurnUpAngle ,TurnAngle,-TurnUpAngle ]
	TurnLeft_Down = [ TurnAngle,-OriStep,TurnAngle,-OriStep ,TurnAngle,-OriStep ]
	TurnLeft_UpTurn = [ TurnAngle,-TurnUpAngle,TurnAngle,-TurnUpAngle ,TurnAngle,-TurnUpAngle ]

########TT4腿蜘蛛自转步态向左########
	FourTurnL_Up = [0,-FourStepUp,0,-FourStepUp ]
	FourTurnL_Turn = [ FourStepTurn,-FourStepUp, FourStepTurn,-FourStepUp ]
	FourTurnL_TurnDown = [ FourStepTurn,-FourStepDown, FourStepTurn,-FourStepDown ]

########TT4腿蜘蛛匍匐自转步态向左########
	DownFourTurnL_Up = [0,-DownFourStepUp,0,-DownFourStepUp ]
	DownFourTurnL_Turn = [ FourStepTurn,-DownFourStepUp, FourStepTurn,-DownFourStepUp ]
	DownFourTurnL_TurnDown = [ FourStepTurn,-DownFourStepDown, FourStepTurn,-DownFourStepDown ]

########################向右步态########################
########TTT6腿蜘蛛向右直走########
	Step_RightMoveInit = [ 0,RightMoveInitStep,0,RightMoveInitStep,0,RightMoveInitStep,0,RightMoveInitStep,0,RightMoveInitStep,0,RightMoveInitStep ]
	Step_RightMoveFirst = [ 0,RightMoveInitSmallStep, 0,RightMoveInStep,  0,RightMoveInitSmallStep,  0,RightMoveOutStep,  0,RightMoveInStep,  0,RightMoveOutStep ]
	Step_RightMoveSecond = [ 0,RightMoveInitSmallStep, 0,-30,  0,RightMoveInitSmallStep,  0,RightMoveInStep,  0,-30,  0,RightMoveInStep ]
	Step_RightMoveThird = [ 0,RightMoveInitStep, 0,-30,  0,RightMoveInitStep,  0,RightMoveInitStep,  0,-30,  0,RightMoveInitStep ]

########TTT6腿蜘蛛自转步态向右########
	TurnRight_Up = [ 0,-TurnUpAngle,0,-TurnUpAngle ,0,-TurnUpAngle ]
	TurnRight_Turn = [ -TurnAngle,-TurnUpAngle,-TurnAngle,-TurnUpAngle ,-TurnAngle,-TurnUpAngle ]
	TurnRight_Down = [ -TurnAngle,-OriStep,-TurnAngle,-OriStep ,-TurnAngle,-OriStep ]
	TurnRight_UpTurn = [ -TurnAngle,-TurnUpAngle,-TurnAngle,-TurnUpAngle ,-TurnAngle,-TurnUpAngle ]

########TT4腿蜘蛛自转步态向右########
	FourTurnR_Up = [ 0,-FourStepUp,0,-FourStepUp ]
	FourTurnR_Turn = [ -FourStepTurn,-FourStepUp, -FourStepTurn,-FourStepUp ]
	FourTurnR_TurnDown = [- FourStepTurn,-FourStepDown, -FourStepTurn,-FourStepDown ]

########TT4腿蜘蛛匍匐自转步态向右########
	DownFourTurnR_Up = [ 0,-DownFourStepUp,0,-DownFourStepUp ]
	DownFourTurnR_Turn = [ -FourStepTurn,-DownFourStepUp, -FourStepTurn,-DownFourStepUp ]
	DownFourTurnR_TurnDown = [- FourStepTurn,-DownFourStepDown, -FourStepTurn,-DownFourStepDown ]

########################做动作表演########################
########TTT6腿蜘蛛蹲下站立########
	Step_Up = [ 0,-Stand,0,-Stand, 0,-Stand, 0,-Stand, 0,-Stand, 0,-Stand ]
	Step_Down = [ 0,-Down,0,-Down, 0,-Down, 0,-Down, 0,-Down, 0,-Down ]

########TT4腿蜘蛛蹲下站立########
	Step_UpFour = [ 0,-Stand,0,-Stand, 0,-Stand, 0,-Stand, 0,-Stand, 0,-Stand ]
	Step_DownFour = [ 0,-Down,0,-Down, 0,-Down, 0,-Down, 0,-Down, 0,-Down ]

########TTT6腿蜘蛛打招呼########
	DoubleLegTurn = [ -FrontLeg,FrontHand,-MiddleLeg,-MiddleHand,BackLeg, -BackHand,FrontLeg,FrontHand,MiddleLeg,-MiddleHand,BackLeg, -BackHand]
	DoubleLegHangUp = [ -FrontLeg,HandRangeHigh,FrontLeg, HandRangeHigh ]
	DoubleLegHangDown = [ -FrontLeg,-HandRangeLow,FrontLeg, -HandRangeLow ]
	DoubleLegHangLeft = [ -LegRangeHigh,0,LegRangeHigh, 0 ]
	DoubleLegHangRight = [ -LegRangeLow,0,LegRangeLow, 0 ]

########TT4腿蜘蛛打招呼########
	LegHelloInit = [-70,-65,10,-65,0,10,-10,-65]
	LegTurnLeftFour = [HandRangeHigh,LegRangeHighFour ]
	LegTurnRightFour = [-HandRangeLow,LegRangeHighFour ]	
	LegHangUpFour = [0,LegRangeHighFour ]
	LegHangDownFour = [0,LegRangeLowFour ]

########TTT6腿蜘蛛俯卧撑########
	SportInit = [ 45,SportUp,0,SportUp,45, -30, -45,SportUp,0,SportUp,-45, -30 ]
	Sportup = [SportUp,SportUp, SportUp, SportUp ]
	Sportdown = [ SportDown,SportDown, SportDown, SportDown ]

########TT４腿蜘蛛俯卧撑########
	SportInitFour = [ 45,SportUp,45, -30, -45,SportUp,-45, -30 ]
	SportInitFour1 =[-75,-65,25,-30,0,10,-25,-30]#单手俯卧撑
	SportInitFour2 =[-75,-20,25,-30,0,10,-25,-30]#单手俯卧撑下去
	SportupFour = [45,SportUp, -45, SportUp ]
	SportdownFour = [ 45,SportDown, -45, SportDown ]
	SportInitFourSingleHand = [ 45,SportUp,45, -30, 0,0,-45, -30 ]
	SportupFourSingleHand = [ 0,SportUp, 0,0 ]
	SportdownFourSingleHand = [ 0,SportDown, 0,0 ]

#########RGB彩灯
	RgbValue = [[255,1,1],[1,255,1],[1,1,255],[255,255,1],[255,1,255],[1,255,255],[255,255,255],[255,100,1],[1,1,1]]

########TTT6腿蜘蛛跳舞########
##效果１
	DanceFirst = [DanceUp,DanceUp ]
	DanceSecond = [ DanceDown,DanceDown ]
##效果２
	DanceFirst1 = [ DanceUp,DanceUp ,DanceDown,DanceDown,DanceDown,DanceDown ]
	DanceSecond1 = [ DanceDown,DanceDown, DanceDown,DanceDown,DanceUp,DanceUp ]
	DanceThird1 = [ DanceDown,DanceDown,DanceUp,DanceUp,DanceDown,DanceDown ]


########TT4腿蜘蛛跳舞########
	DanceFirstFour = [ DanceUp,DanceDown,DanceDown,DanceDown ]
	DanceSecondFour = [ DanceDown,DanceUp,DanceDown, DanceDown ]
	DanceThirdFour = [ DanceDown,DanceDown,DanceDown,DanceUp ]
	DanceFourthFour = [ DanceDown,DanceDown,DanceUp,DanceDown ]

########TT4腿蜘蛛防御动作演示########
	HangTailTurn1 = 25
	HangTailTurn2 = 75
	HangTailBackLegStand = 90
	BattleStand = 90
	BattleStandInit = 80
	BattleSit = 65
	MoveBodyTurn = 45
	HangTailInit = [-45,0,45,-HangTailBackLegStand,45,0,-45,-HangTailBackLegStand] 
	HangTailLeftTurn = [-45,0,HangTailTurn1,-90,45,0,-HangTailTurn2,-90]
	HangTailRightTurn = [-45,0,HangTailTurn2,-90,45,0,-HangTailTurn1,-90]
	BattleInit = [-45,-BattleStandInit,45,-BattleStandInit,45,-BattleStandInit,-45,-BattleStandInit]
	BattleMoveForward = [-45,-BattleSit,45,-BattleStand,45,-BattleSit,-45,-BattleStand]
	BattleMoveBack = [-45,-BattleStand,45,-BattleSit,45,-BattleStand,-45,-BattleSit]
	MoveBodyLTurn = [MoveBodyTurn,-90,MoveBodyTurn,-90,MoveBodyTurn,-90,MoveBodyTurn,-90]
	MoveBodyRTurn = [-MoveBodyTurn,-90,-MoveBodyTurn,-90,-MoveBodyTurn,-90,-MoveBodyTurn,-90]

	rs=[]
	InitPosition=[]
	MoveCount = 0

#点阵显示　　大眼　委屈　鄙视　无语　惊喜　左眨眼　右眨眼　开心　伤心 无　向上箭头 向下箭头　向左箭头　向右箭头 双手俯卧撑　单手俯卧撑　　蹲下　起立  R G B
	DisplayData = [[0x36,0x49,0x49,0x00,0x3E],[0x63,0x14,0x22,0x00,0x3E],[0x77,0x44,0x00,0x2A,0x14],
			[0x41,0x36,0x00,0x1C,0x22],[0x22,0x77,0x22,0x1C,0x14],[0x20,0x12,0x20,0x08,0x1C],
			[0x02,0x24,0x02,0x08,0x1C],[0x36,0x49,0x49,0x22,0x3E],[0x36,0x49,0x49,0x3E,0x22],
			[0x00,0x00,0x00,0x00,0x00],[0x08,0x1C,0x2A,0x08,0x08],[0x08,0x08,0x2A,0x1C,0x08],
			[0x08,0x10,0x3F,0x10,0x08],[0x08,0x04,0x7E,0x04,0x08],[0x00,0x00,0xFF,0x14,0x22],
			[0x00,0x00,0xFC,0x14,0x22],[0x00,0x14,0x08,0x14,0x00],[0x22,0x14,0x08,0x14,0x22],
			[0x1C,0x14,0x1C,0x14,0x12],[0x38,0x26,0x22,0x3E,0x02],[0x1E,0x12,0x14,0x12,0x1E]]

###初始化
	def __init__(self):
		self.mlib = MiniBotControlLib("udp_mode")
		r = self.mlib.Connect("10.10.100.254",8899)
		if(r > 0):
			print("机器人连接成功")
		else:
			print("机器人连接失败")
		self.rs = self.mlib.ScanId(0,50)
		# del self.rs[0][0]
		print(self.rs[0]) 
		#六腿蜘蛛
		# for a in range(0,12): 
		# 	self.mlib.SetMotorMode(self.rs[0][a],0)
		# self.InitPosition = [ 0,-70,0,-70,0,-70,0,-70,0,-70,0,-70] 
		#四腿蜘蛛
		# for a in range(0,8):  
			# self.mlib.SetMotorMode(self.rs[0][a],0)
		# self.InitPosition = [ 0,-70,0,-70,0,-70,0,-70]
		#六腿TTT蜘蛛
		# for a in range(0,18):   
		# 	self.mlib.SetMotorMode(self.rs[0][a],0)					
		# self.InitPosition = [ -90,-90,-90,-90,-90,0,20,0,20,0,20,0,20,0,20,-90,0,20]
		#小狗步态
		# for a in range(0,４):   
		# 	self.mlib.SetMotorMode(self.rs[0][a],0)					
		# res=self.mlib.SetPositionSync(self.rs[0],self.FourDog_InitF)#小狗前进初始化
		# res=self.mlib.SetPositionSync(self.rs[0],self.FourDog_InitB)#小狗后退初始化	

		# res=self.mlib.SetPositionSync(self.rs[0],self.InitPosition)
		time.sleep(self.TIME)

		print ('欢迎进入多足机器人玩法，请输入按键控制机器人:')

	###快速初始化
	def QuickInit(self):
		self.mlib.SetPositionSync(self.rs[0],self.InitPosition)
		time.sleep(self.TIMES)


	###六腿蜘蛛前进步态
	def SpiderForward(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0_2_4,self.StepForward_UpFirst,self.SPEED6)#024脚抬起
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg_LRArm, self.StepForward_135Re024Forward,self.SPEED6)#135腿恢复（脚尖不动），同时024向前迈
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0_2_4, self.StepForward_DownFirst,self.SPEED6)#024脚落下
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg1_3_5, self.StepForward_UpSecond,self.SPEED6)#135脚抬起
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg_LRArm, self.StepForward_024Re135Forward,self.SPEED6)#024腿恢复（脚尖不动），同时135向前迈
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg1_3_5, self.StepForward_DownSecond,self.SPEED6)#135脚落下
		time.sleep(self.TIME)

	###四腿蜘蛛前进步态
	def SpiderFourForward(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg05,self.FourForwardUp,self.SPEED4)#05脚抬起
		time.sleep(0.25)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.FourForward23Re05Forward,self.SPEED8)#23腿恢复（脚尖不动），同时05向前迈
		time.sleep(0.25)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self.FourForwardDown,self.SPEED4)#05脚落下
		time.sleep(0.25)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self. FourForwardUp,self.SPEED4)#23脚抬起
		time.sleep(0.25)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.FourForward05Re23Forward,self.SPEED8)#05腿恢复（脚尖不动），同时23向前迈
		time.sleep(0.25)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.FourForwardDown,self.SPEED4)#23脚落下
		time.sleep(0.25)	

###四腿蜘蛛匍匐前进步态
	def SpiderFourDownForward(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg05,self.DownFourForwardUp,self.SPEED4)#05脚抬起
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.DownFourForward23Re05Forward,self.SPEED8)#23腿恢复（脚尖不动），同时05向前迈
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self.DownFourForwardDown,self.SPEED4)#05脚落下
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.DownFourForwardUp,self.SPEED4)#23脚抬起
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.DownFourForward05Re23Forward,self.SPEED8)#05腿恢复（脚尖不动），同时23向前迈
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.DownFourForwardDown,self.SPEED4)#23脚落下
		time.sleep(self.TIME)	

	###小狗前进步态
	def DogFourForward(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235,self.FourDog8Leg1F,self.SPEED8)#05腿恢复，23抬
		time.sleep(self.TIMES)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235,self.FourDog8Leg2F,self.SPEED8)#23恢复，05抬
		time.sleep(self.TIMES)

	###六腿蜘蛛后退步态
	def SpiderBack(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0_2_4,self.StepBack_UpFirst,self.SPEED6)#024脚抬起
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg_LRArm, self.StepBack_135Re024Back,self.SPEED6)#135腿恢复（脚尖不动），同时024向前迈
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0_2_4, self.StepBack_DownFirst,self.SPEED6)#024脚落下
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg1_3_5, self.StepBack_UpSecond,self.SPEED6)#135脚抬起
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg_LRArm, self.StepBack_024Re135Back,self.SPEED6)#024腿恢复（脚尖不动），同时135向前迈
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg1_3_5, self. StepBack_DownSecond,self.SPEED6)#135脚落下
		time.sleep(self.TIME)

	###四腿蜘蛛后退步态
	def SpiderFourBack(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg05,self.FourBackUp,self.SPEED4)#05脚抬起
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.FourBack23Re05Back,self.SPEED8)#23腿恢复（脚尖不动），同时05向后迈
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self.FourBackDown,self.SPEED4)#05脚落下
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self. FourBackUp,self.SPEED4)#23脚抬起
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self. FourBack05Re23Back,self.SPEED8)#05腿恢复（脚尖不动），同时23向后迈
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.FourBackDown,self.SPEED4)#23脚落下
		time.sleep(self.TIME)

	###四腿蜘蛛匍匐后退步态
	def SpiderFourDownBack(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg05,self.DownFourBackUp,self.SPEED4)#05脚抬起
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.DownFourBack23Re05Back,self.SPEED8)#23腿恢复（脚尖不动），同时05向后迈
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self.DownFourBackDown,self.SPEED4)#05脚落下
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.DownFourBackUp,self.SPEED4)#23脚抬起
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.DownFourBack05Re23Back,self.SPEED8)#05腿恢复（脚尖不动），同时23向后迈
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.DownFourBackDown,self.SPEED4)#23脚落下
		time.sleep(self.TIME)

	###小狗后退步态
	def DogFourBack(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235,self.FourDog8Leg1B,self.SPEED8)#05腿恢复，23抬
		time.sleep(self.TIMES)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235,self.FourDog8Leg2B,self.SPEED8)#23恢复，05抬
		time.sleep(self.TIMES)

	###六腿蜘蛛原地向右转圈
	def SpiderTurn_R(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0_2_4, self.Step_init,self.SPEED6)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg1_3_5, self.Step_init,self.SPEED6)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0_2_4, self.TurnRight_Up,self.SPEED6)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0_2_4, self. TurnRight_Turn,self.SPEED6)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0_2_4, self.TurnRight_Down,self.SPEED6) 
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg1_3_5, self.TurnRight_Up,self.SPEED6)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg1_3_5, self.TurnRight_Turn,self.SPEED6)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg1_3_5, self.TurnRight_Down,self.SPEED6) 
		time.sleep(self.TIME)

	###四腿蜘蛛原地向右转圈
	def SpiderFourTurn_R(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg05,self.FourForwardInit,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.FourForwardInit,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self.FourTurnR_Up,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self. FourTurnR_Turn,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self.FourTurnR_TurnDown,self.SPEED4) 
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.FourTurnR_Up,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self. FourTurnR_Turn,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.FourTurnR_TurnDown,self.SPEED4) 
		time.sleep(self.TIME)

	###四腿蜘蛛匍匐原地向右转圈
	def SpiderFourDownTurn_R(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg05,self.DownFourForwardInit,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.DownFourForwardInit,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self.DownFourTurnR_Up,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self. DownFourTurnR_Turn,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self.DownFourTurnR_TurnDown,self.SPEED4) 
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.DownFourTurnR_Up,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self. DownFourTurnR_Turn,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.DownFourTurnR_TurnDown,self.SPEED4) 
		time.sleep(self.TIME)

	###六腿蜘蛛原地向左转圈
	def SpiderTurn_L(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0_2_4, self.Step_init,self.SPEED6)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg1_3_5, self.Step_init,self.SPEED6)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0_2_4, self.TurnLeft_Up,self.SPEED6)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0_2_4, self. TurnLeft_Turn,self.SPEED6)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0_2_4, self.TurnLeft_Down,self.SPEED6) 
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg1_3_5, self.TurnLeft_Up,self.SPEED6)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg1_3_5, self.TurnLeft_Turn,self.SPEED6)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg1_3_5, self.TurnLeft_Down,self.SPEED6) 
		time.sleep(self.TIME)

	###四腿蜘蛛原地向左转圈
	def SpiderFourTurn_L(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg05,self.FourForwardInit,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.FourForwardInit,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self.FourTurnL_Up,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self. FourTurnL_Turn,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self.FourTurnL_TurnDown,self.SPEED4) 
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.FourTurnL_Up,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self. FourTurnL_Turn,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.FourTurnL_TurnDown,self.SPEED4) 
		time.sleep(self.TIME)

	###四腿蜘蛛匍匐原地向左转圈
	def SpiderFourDownTurn_L(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg05,self.DownFourForwardInit,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.DownFourForwardInit,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self.DownFourTurnL_Up,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self. DownFourTurnL_Turn,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg05, self.DownFourTurnL_TurnDown,self.SPEED4) 
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.DownFourTurnL_Up,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self. DownFourTurnL_Turn,self.SPEED4)
		time.sleep(self.TIME)
		self.mlib.SetPositionSyncWithSpeeds(self.leg23, self.DownFourTurnL_TurnDown,self.SPEED4) 
		time.sleep(self.TIME)

	###六腿蜘蛛蹲下起立
	def SpiderUpAndDown(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg_all, self.Step_Down,self.SPEED12) 
		time.sleep(self.TIMES)
		self.mlib.SetPositionSyncWithSpeeds(self.leg_all, self.Step_Up,self.SPEED12)
		time.sleep(self.TIMES)

	###四腿蜘蛛蹲下起立
	def SpiderFourUpAndDown(self):
		self.mlib.SetDevData(9,0x01,self.DisplayData[16])
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.Step_DownFour,self.SPEED8) 
		time.sleep(self.TIMES)
		self.mlib.SetDevData(9,0x01,self.DisplayData[17])
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.Step_UpFour,self.SPEED8)
		time.sleep(self.TIMES)

	###六腿蜘蛛打招呼
	def SpiderSayHello(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg_all, self.DoubleLegTurn,self.SPEED12) 
		time.sleep(self.TIMES)
		for SayhelloCount1 in range(0,2):
			self.mlib.SetPositionSyncWithSpeeds(self.leg03, self.DoubleLegHangLeft,self.SPEED4) 
			time.sleep(self.TIMES)
			self.mlib.SetPositionSyncWithSpeeds(self.leg03, self.DoubleLegHangRight,self.SPEED4) 
			time.sleep(self.TIMES)
		for SayhelloCount2 in range(0,2):
			self.mlib.SetPositionSyncWithSpeeds(self.leg03, self.DoubleLegHangUp,self.SPEED4) 
			time.sleep(self.TIMES)
			self.mlib.SetPositionSyncWithSpeeds(self.leg03, self.DoubleLegHangDown,self.SPEED4) 
			time.sleep(self.TIMES)

	###四腿蜘蛛打招呼
	def SpiderFourSayHello(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.LegHelloInit,self.SPEED8) 
		time.sleep(self.TIMES)
		for SayhelloCount1 in range(0,2):
			self.mlib.SetPositionSyncWithSpeeds(self.leg_RArmFour, self.LegTurnLeftFour,self.SPEED2) 
			time.sleep(0.7)
			self.mlib.SetDevData(8,0x02,self.RgbValue[0])
			self.mlib.SetPositionSyncWithSpeeds(self.leg_RArmFour, self.LegTurnRightFour,self.SPEED2) 
			time.sleep(0.7)
			self.mlib.SetDevData(8,0x02,self.RgbValue[1])
		for SayhelloCount2 in range(0,2):
			self.mlib.SetPositionSyncWithSpeeds(self.leg_RArmFour, self.LegHangUpFour,self.SPEED2) 
			time.sleep(0.7)
			self.mlib.SetDevData(8,0x02,self.RgbValue[2])
			self.mlib.SetPositionSyncWithSpeeds(self.leg_RArmFour, self.LegHangDownFour,self.SPEED2) 
			time.sleep(0.7)
			self.mlib.SetDevData(8,0x02,self.RgbValue[5])

	###六腿蜘蛛俯卧撑
	def SpiderSport(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg_all, self.SportInit,self.SPEED12) 
		time.sleep(0.7)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0134, self.Sportup,self.SPEED8)
		time.sleep(0.7)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0134, self.Sportdown,self.SPEED8)
		time.sleep(0.7)

	###四腿蜘蛛俯卧撑		
	def SpiderSportFour(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.SportInitFour,self.SPEED8) 
		time.sleep(0.7)
		self.mlib.SetPositionSyncWithSpeeds(self.leg03, self.SportupFour,self.SPEED4)
		time.sleep(0.7)
		self.mlib.SetPositionSyncWithSpeeds(self.leg03, self.SportdownFour,self.SPEED4)
		time.sleep(0.7)

	###四腿单手蜘蛛俯卧撑		
	def SpiderSportFourSingleHand(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.SportInitFour1,self.SPEED8) 
		time.sleep(0.7)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.SportInitFour2,self.SPEED8)
		time.sleep(0.7)
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.SportInitFour1,self.SPEED8)
		time.sleep(0.7)

	###四腿蜘蛛跳舞
	def SpiderFourDance(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.Step_Up,self.SPEED12)
		time.sleep(0.7)
		self.mlib.SetPositionSyncWithSpeeds(self.leg_danceFour, self.DanceFirstFour,self.SPEED4) 
		time.sleep(0.7)
		self.mlib.SetPositionSyncWithSpeeds(self.leg_danceFour, self.DanceSecondFour,self.SPEED4)
		time.sleep(0.7)
		self.mlib.SetPositionSyncWithSpeeds(self.leg_danceFour, self.DanceThirdFour,self.SPEED4)
		time.sleep(0.7) 
		self.mlib.SetPositionSyncWithSpeeds(self.leg_danceFour, self.DanceFourthFour,self.SPEED4)
		time.sleep(0.7) 

	###四腿蜘蛛跳舞加点阵
	def SpiderFourDance1(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.Step_Up,self.SPEED12)
		time.sleep(0.7)		
		self.mlib.SetPositionSyncWithSpeeds(self.leg_danceFour, self.DanceFirstFour,self.SPEED4) 
		self.mlib.SetDevData(9,0x01,self.DisplayData[1])
		time.sleep(0.7)
		self.mlib.SetPositionSyncWithSpeeds(self.leg_danceFour, self.DanceSecondFour,self.SPEED4)
		self.mlib.SetDevData(9,0x01,self.DisplayData[2])
		time.sleep(0.7)
		self.mlib.SetPositionSyncWithSpeeds(self.leg_danceFour, self.DanceThirdFour,self.SPEED4)
		self.mlib.SetDevData(9,0x01,self.DisplayData[1])
		time.sleep(0.7) 
		self.mlib.SetPositionSyncWithSpeeds(self.leg_danceFour, self.DanceFourthFour,self.SPEED4)
		self.mlib.SetDevData(9,0x01,self.DisplayData[2])
		time.sleep(0.7) 

	###六腿蜘蛛跳舞
	def SpiderDance(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg_dance, self.DanceFirst1,self.SPEED6) 
		time.sleep(self.TIMES)
		self.mlib.SetPositionSyncWithSpeeds(self.leg_dance, self.DanceSecond1,self.SPEED6)
		time.sleep(self.TIMES)
		self.mlib.SetPositionSyncWithSpeeds(self.leg_dance, self.DanceThird1,self.SPEED6)
		time.sleep(self.TIMES) 

######防御机器人######
	###四腿蜘蛛摇尾巴　蓝色
	def SpiderFourHangTail(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.HangTailInit,self.SPEED8) 
		time.sleep(self.TIMES)
		for a in range (0,3):
			self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.HangTailLeftTurn,self.SPEED8)
			time.sleep(0.7)
			self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.HangTailRightTurn,self.SPEED8)
			time.sleep(0.7) 
 		
	###四腿蜘蛛战斗防御　红色
	def SpiderFourBattle(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.BattleInit,self.SPEED8) 
		time.sleep(self.TIMES)
		for a in range (0,4):
			self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.BattleMoveForward,self.SPEED8)
			time.sleep(0.55)
			self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.BattleMoveBack,self.SPEED8)
			time.sleep(0.55) 

	###四腿蜘蛛扭动身体防御 绿色
	def SpiderFourMoveBody(self):
		self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.InitPosition,self.SPEED8) 
		time.sleep(self.TIMES)
		for a in range (0,3):
			self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.MoveBodyLTurn,self.SPEED8)
			time.sleep(0.8)
			self.mlib.SetPositionSyncWithSpeeds(self.leg0235, self.MoveBodyRTurn,self.SPEED8)
			time.sleep(0.8) 


	###四足蜘蛛前进、后退、左转、右转各两个循环  
	def SpiderFourDemo(self):
		for self.MoveCount in range(0,2):
			print('向前走')
			self.SpiderFourForward()
		time.sleep(1)
		for self.MoveCount in range(0,2):
			print('向后走')
			self.SpiderFourBack()
		time.sleep(1)
		# for self.MoveCount in range(0,2):
		# 	self.BipeSlide_L()
		# for self.MoveCount in range(0,2):
		# 	self.BipeSlide_R()
		for self.MoveCount in range(0,4):
			print('向左转向')
			self.SpiderFourTurn_L()
		time.sleep(1)
		for self.MoveCount in range(0,4):
			print('向右转向')
			self.SpiderFourTurn_R()
		time.sleep(1)
		# for self.MoveCount in range(0,3):
		# 	print('向前走')
		# 	self.SpiderFourForward()
		# time.sleep(1)
		# for self.MoveCount in range(0,6):
		# 	print('匍匐向前走')
		# 	self.SpiderFourDownForward()
		# time.sleep(1)
		# for self.MoveCount in range(0,3):
		# 	print('向前走')
		# 	self.SpiderFourForward()
		time.sleep(1)
		self.QuickInit()


#######穿越火线
	def CrossFire_DisPlay(self):
		while 1:
			if(self.Threading==0):
				self.mlib.SetDevData(9,0x01,self.DisplayData[5])
				time.sleep(self.TIMES)
				self.mlib.SetDevData(9,0x01,self.DisplayData[6])
				time.sleep(self.TIMES)
			else:
				self.mlib.SetDevData(9,0x01,self.DisplayData[1])
				print("display")
				time.sleep(self.TIMES)

	def CrossFire(self):
			#---------创建线程对象----
		self.threading_1 = threading.Thread(target=self.CrossFire_DisPlay, args=())       #args内是传递给函数的参数，必须是可迭代对象，通常使用元组
		self.threading_2 = threading.Thread(target=self.CrossFire_Measure, args=())	
			#--------开启线程-----
		self.threading_1.start()
		self.threading_2.start()
		while 1:
			if(self.Threading==0):
				self.SpiderFourForward()
			else:
				for a in range (0,5):
					self.SpiderFourDownForward()
				self.Threading = 0
				# self.CrossFire_measure()
			print("over")		

	def CrossFire_Measure(self):
		while 1:
			s3 = self.mlib.GetDevData(31,1)
			dcm = (331.5 + 0.6 * 25) * (s3 * 0.000001) / 2 * 100 #由M 转CM *100
			# time.sleep(0.2)
			print("超声波返回数据：%.1fcm" % dcm)
			if (dcm<=25 and dcm>0):	
				self.Threading = 1 ##是否开通线程标志位
				print("仿生蜘蛛匍匐前进")


######迎宾机器人 声音传感器接D3接口		
	def WelcomeRobot(self):
					#---------创建线程对象----
		# self.threading_1 = threading.Thread(target=self.WelcomeRobot_Measure, args=())       	
		# 	#--------开启线程-----
		# self.threading_1.start()
		# print("kaiqi")
		# while 1:
		# 	voice = self.mlib.GetDevData(9,3)
		# 	print("检测声音")
		# 	if(self.Threading==0):
		# 		print("没有声音")
		# 	else:
		# 		self.SpiderFourSayHello()
		# 		self.Threading = 0
		while 1:
			voice = self.mlib.GetDevData(9,3)
			print("检测声音")
			if(voice==0):
				print("没有声音")
				self.mlib.SetDevData(8,0x02,self.RgbValue[9])
				self.mlib.SetDevData(8,0x02,self.RgbValue[8])				
			else:
				print("有声音")
				self.mlib.SetDevData(9,0x01,self.DisplayData[7])
				self.SpiderFourSayHello()


	def WelcomeRobot_Measure(self):
		while 1:
			voice = self.mlib.GetDevData(9,3)
			print("检测声音")
			if (voice == 1):	
				self.mlib.SetDevData(9,0x01,self.DisplayData[7])
				self.Threading = 1 ##是否开通线程标志位
				for a in range(0,9):
					self.mlib.SetDevData(8,0x02,self.RgbValue[a])
					time.sleep(TIMES)
			else:
				self.mlib.SetDevData(8,0x02,self.RgbValue[3])
				self.mlib.SetDevData(9,0x01,self.DisplayData[9])				


######动感机器人 声音传感器接D2接口
	def DanceRobot_Display(self):
		while 1:
			if(self.Threading==1):
				self.mlib.SetDevData(9,0x01,self.DisplayData[1])
				time.sleep(self.TIMES)
				self.mlib.SetDevData(9,0x01,self.DisplayData[2])
				time.sleep(self.TIMES)
			else:
				self.mlib.SetDevData(9,0x01,self.DisplayData[9])
				print("display")
				time.sleep(self.TIMES)
		 

	def DanceRobot(self):
		#---------创建线程对象----
		threading_1 = threading.Thread(target=self.DanceRobot_Display, args=())       #args内是传递给函数的参数，必须是可迭代对象，通常使用元组
		#--------开启线程-----
		threading_1.start()	
		while 1:
			voice = self.mlib.GetDevData(9,0x02)
			if (voice == 1):
				self.Threading = 1
				self.SpiderFourDance()
				self.Threading = 0				
			else:
				print("没有声音")


######跟随机器人 
	def FollowRobot(self):		
		s3 = self.mlib.GetDevData(31,1)
		dcm = (331.5 + 0.6 * 25) * (s3 * 0.000001) / 2 * 100 #由M 转CM *100
		print("超声波返回数据：%.1fcm" % dcm)
		if(dcm>=15):
			self.mlib.SetDevData(9,0x01,self.DisplayData[10])
			self.SpiderFourForward()
		else:
			self.mlib.SetDevData(9,0x01,self.DisplayData[11])
			self.SpiderFourBack()

######避障机器人
	def AvoidanceObsRobot(self):
		s3 = self.mlib.GetDevData(31,1)
		dcm = (331.5 + 0.6 * 25) * (s3 * 0.000001) / 2 * 100 #由M 转CM *100
		print("超声波返回数据：%.1fcm" % dcm)
		if(dcm<=15 and dcm>0):
			self.mlib.SetDevData(9,0x01,self.DisplayData[3])
			for a in range(0,4):
				self.SpiderFourTurn_L()
			for a in range(0,11):
				self.SpiderFourForward()
			for a in range(0,3):
				self.SpiderFourTurn_R()
			for a in range(0,8):
				self.SpiderFourForward()
			for a in range(0,2):
				self.SpiderFourTurn_R()
			for a in range(0,8):
				self.SpiderFourForward()
			for a in range(0,4):
				self.SpiderFourTurn_L()
		else:
			self.mlib.SetDevData(9,0x01,self.DisplayData[0])
			self.SpiderFourForward()


######巡线机器人
	def LinePatrolRobot(self):			
		s3 = mlib.GetDevData(15,0x03)
		s4 = mlib.GetDevData(15,0x07)
		if(s3==1 and s4==1):
			self.mlib.SetDevData(9,0x01,self.DisplayData[11])
			self.SpiderFourTurn_L()
		elif(s3==0 and s4==0):
			self.mlib.SetDevData(9,0x01,self.DisplayData[10])
			self.SpiderFourForward()
		elif(s3==1 and s4==0):
			self.mlib.SetDevData(9,0x01,self.DisplayData[12])
			for a in range (0,1):
				self.SpiderFourTurn_L()
		else:
			self.mlib.SetDevData(9,0x01,self.DisplayData[13])
			for a in range (0,1):
				self.SpiderFourTurn_R()	

######遥控机器人
	def RemoteRobot(self):
		self.mlib.SetDevData(6,0x01,self.SensorOn)
		while 1:
			s1 = self.mlib.ReadDevData(6,0x01)
			print ("返回值：",s1)
			if(s1==2):
				print("按下＂＋＂－－向前走")
				self.mlib.SetDevData(9,0x01,self.DisplayData[10])
				self.mlib.SetDevData(8,0x02,self.RgbValue[0])
				self.SpiderFourForward()
			if(s1==8):
				print("按下＂－＂－－向后走")
				self.mlib.SetDevData(9,0x01,self.DisplayData[11])
				self.mlib.SetDevData(8,0x02,self.RgbValue[1])
				self.SpiderFourBack()
			if(s1==4):
				print("按下＂←＂－－向左转向")
				self.mlib.SetDevData(9,0x01,self.DisplayData[12])
				self.mlib.SetDevData(8,0x02,self.RgbValue[2])
				self.SpiderFourTurn_L()
			if(s1==6):
				print("按下＂→＂－－向右转向")
				self.mlib.SetDevData(9,0x01,self.DisplayData[13])
				self.mlib.SetDevData(8,0x02,self.RgbValue[3])
				self.SpiderFourTurn_R()	
			if(s1==10):
				print("按下＂1＂－－跳舞")
				self.mlib.SetDevData(9,0x01,self.DisplayData[4])
				self.mlib.SetDevData(8,0x02,self.RgbValue[4])
				self.SpiderFourDance()
			if(s1==11):
				print("按下＂2＂－－俯卧撑")
				self.mlib.SetDevData(9,0x01,self.DisplayData[0])
				self.mlib.SetDevData(8,0x02,self.RgbValue[7])
				self.SpiderSportFour()


######手势遥控机器人
	def GestureRemoteRobot(self):
		while 1:
			s3 = self.mlib.SetDevData(12,0x01,self.SensorOn)
			s1 = self.mlib.GetDevData(12,0x01)
			print ("返回值：",s1)
			if(s1==1):
				print("向前走")
				self.mlib.SetDevData(9,0x01,self.DisplayData[10])
				self.SpiderFourForward()
			if(s1==2):
				print("向后走")
				self.mlib.SetDevData(9,0x01,self.DisplayData[11])
				self.SpiderFourBack()
			if(s1==3):
				print("向左转向")
				self.mlib.SetDevData(9,0x01,self.DisplayData[12])
				self.SpiderFourTurn_L()
			if(s1==4):
				print("向右转向")
				self.mlib.SetDevData(9,0x01,self.DisplayData[13])
				self.SpiderFourTurn_R()	

######变脸机器人
	def TransFaceRobot_Action(self):
		while 1:
			for a in range (0,2):
				self.SpiderFourForward()
			time.sleep(1)
			for a in range (0,2):
				self.SpiderFourBack()

	def TransFaceRobot_Display(self):
		while 1:
			s3 = self.mlib.GetDevData(31,1)
			dcm = (331.5 + 0.6 * 25) * (s3 * 0.000001) / 2 * 100 #由M 转CM *100
			print("超声波返回数据：%.1fcm" % dcm)
			if(dcm>15 and dcm<=30):
				self.mlib.SetDevData(9,0x01,self.DisplayData[self.FaceFlag])
				self.mlib.SetDevData(8,0x02,self.RgbValue[self.FaceFlag])
				self.FaceFlag += 1
				if(self.FaceFlag==9):
					self.FaceFlag=0

	def TransFaceRobot(self):
		# threading_1 = threading.Thread(target=self.TransFaceRobot_Action, args=())       #args内是传递给函数的参数，必须是可迭代对象，通常使用元组
		threading_2 = threading.Thread(target=self.TransFaceRobot_Display, args=())
		# threading_1.start()		
		threading_2.start()
		while 1:
			for a in range (0,2):
				self.SpiderFourForward()
			time.sleep(1)
			for a in range (0,2):
				self.SpiderFourBack()

######运动机器人
	def SportRobot(self):
		while 1:
			self.mlib.SetDevData(6,0x01,self.SensorOn)
			s1 = self.mlib.ReadDevData(6,0x01)
			print ("返回值：",s1)
			if(s1==10):
				print("按下＂1＂－－单手俯卧撑")
				self.mlib.SetDevData(9,0x01,self.DisplayData[15])
				self.mlib.SetDevData(8,0x02,self.RgbValue[0])
				self.SpiderSportFourSingleHand()
			if(s1==11):
				print("按下＂2＂－－双手俯卧撑")
				self.mlib.SetDevData(9,0x01,self.DisplayData[14])
				self.mlib.SetDevData(8,0x02,self.RgbValue[1])
				self.SpiderSportFour()
			if(s1==12):
				print("按下＂3＂－－蹲下起立")
				self.mlib.SetDevData(8,0x02,self.RgbValue[2])
				self.SpiderFourUpAndDown()

######防御机器人
	def DefenseRobot(self):
	##颜色传感器 1:red  2:green  3:blue
		while 1:
			s3 = mlib.GetDevData(28,1)
			print(s3)
			if(s3==2):
				self.mlib.SetDevData(9,0x01,self.DisplayData[19])
				self.mlib.SetDevData(8,0x02,self.RgbValue[1])
				self.SpiderFourMoveBody()
				self.QuickInit()
			elif(s3==3):
				self.mlib.SetDevData(9,0x01,self.DisplayData[20])
				self.mlib.SetDevData(8,0x02,self.RgbValue[2])
				self.SpiderFourHangTail()
				self.QuickInit()
			elif(s3==1):
				self.mlib.SetDevData(9,0x01,self.DisplayData[18])
				self.mlib.SetDevData(8,0x02,self.RgbValue[0])
				self.SpiderFourBattle()
				self.QuickInit()
			else:
				self.mlib.SetDevData(8,0x02,self.RgbValue[8])
				self.mlib.SetDevData(9,0x01,self.DisplayData[9])


	def RemoteRobot1(self):
		self.mlib.SetDevData(6,0x01,self.SensorOn)
		while 1:
			s1 = self.mlib.ReadDevData(17,0x03)
			print ("返回值：",s1)
			if(s1==2):
				print("按下＂＋＂－－向前走")
				# self.mlib.SetDevData(9,0x01,self.DisplayData[10])
				time.sleep(1)
				self.mlib.SetDevData(8,0x02,self.RgbValue[0])
				time.sleep(1)
				self.mlib.SetDevData(9,0x01,self.DisplayData[10])
				# self.SpiderFourForward()
			elif(s1==8):
				print("按下＂－＂－－向后走")
				# self.mlib.SetDevData(9,0x01,self.DisplayData[11])
				time.sleep(1)
				self.mlib.SetDevData(8,0x02,self.RgbValue[1])
				time.sleep(1)
				self.mlib.SetDevData(9,0x01,self.DisplayData[11])
				# self.SpiderFourBack()
			elif(s1==4):
				print("按下＂←＂－－向左转向")
				self.mlib.SetDevData(9,0x01,self.DisplayData[12])
				time.sleep(1)
				self.mlib.SetDevData(8,0x02,self.RgbValue[2])
				time.sleep(1)
				# self.SpiderFourTurn_L()
			elif(s1==6):
				print("按下＂→＂－－向右转向")
				self.mlib.SetDevData(9,0x01,self.DisplayData[13])
				time.sleep(1)
				self.mlib.SetDevData(8,0x02,self.RgbValue[3])
				time.sleep(1)
				# self.SpiderFourTurn_R()	
			elif(s1==10):
				print("按下＂1＂－－跳舞")
				self.mlib.SetDevData(9,0x01,self.DisplayData[4])
				self.mlib.SetDevData(8,0x02,self.RgbValue[4])
				# self.SpiderFourDance()
			elif(s1==11):
				print("按下＂2＂－－俯卧撑")
				self.mlib.SetDevData(9,0x01,self.DisplayData[0])
				self.mlib.SetDevData(8,0x02,self.RgbValue[7])
				# self.SpiderSportFour()
			else:
				print("noting")



mlib = MiniBotControlLib("udp_mode")
r = mlib.Connect("10.10.100.254",8899)
if(r > 0):
	print("机器人连接成功")
else:
	print("机器人连接失败")
disdata = [0xfe,0x11,0xff,0x12,0x82]
#大眼　委屈　鄙视　无语　惊喜　左眨眼　右眨眼　开心　伤心 无　向上箭头 向下箭头　向左箭头　向右箭头 双手俯卧撑　单手俯卧撑　　蹲下　起立  R G B
disdata1 = [[0x36,0x49,0x49,0x00,0x3E],[0x63,0x14,0x22,0x00,0x3E],[0x77,0x44,0x00,0x2A,0x14],
			[0x41,0x36,0x00,0x1C,0x22],[0x22,0x77,0x22,0x1C,0x14],[0x20,0x12,0x20,0x08,0x1C],
			[0x02,0x24,0x02,0x08,0x1C],[0x36,0x49,0x49,0x22,0x3E],[0x36,0x49,0x49,0x3E,0x22],
			[0x00,0x00,0x00,0x00,0x00],[0x08,0x1C,0x2A,0x08,0x08],[0x08,0x08,0x2A,0x1C,0x08],
			[0x08,0x10,0x3F,0x10,0x08],[0x08,0x04,0x7E,0x04,0x08],[0x00,0x00,0xFF,0x14,0x22],
			[0x00,0x00,0xFC,0x14,0x22],[0x00,0x14,0x08,0x14,0x00],[0x22,0x14,0x08,0x14,0x22],
			[0x1C,0x14,0x1C,0x14,0x12],[0x38,0x26,0x22,0x3E,0x02],[0x1E,0x12,0x14,0x12,0x1E]]

fish1 = [1]
fish0 = [0]
RgbValue1 = [[255,1,1],[1,255,1],[1,1,255],[1,1,1]]

spider = SpiderModuleRobot()
# ipdb.set_trace()
# s3 = mlib.SetDevData(12,0x01,fish1)

# mlib.SetDevData(6,0x01,fish1)
# mlib.SetDevData(6,0x01,fish1)
while 1:
	print("准备测试")
	
	# spider.SpiderFourHangTail()
	# spider.SpiderFourTurn_R()
	# spider.SpiderFourMoveBody()
	# spider.CrossFire()
	# spider.WelcomeRobot()
	# spider.GestureRemoteRobot()
	spider.RemoteRobot1()
# 	threading_12 = threading.Thread(target=spider.WelcomeRobot_Measure, args=())       	
# 		#--------开启线程-----
# 	threading_12.start()
# 	print("paowan")
# 	while 1:
# 		time.sleep(0.5)
# 		if(spider.Threading==0):
# 			print("没有声音")
# 			spider.SpiderFourSayHello()
# 		else:
# 			print("有声音")
# 			# spider.SpiderFourSayHello()
# 			spider.Threading = 0
# # # ##手势传感器

	# s3 = mlib.GetDevData(12,0x01)
	# print(s3)
	# time.sleep(0.2)

# ##点阵传感器
	# for a in range (0,9):
	# 	print("1")
	# 	time.sleep(1)
	# 	mlib.SetDevData(9,0x01,disdata1[a])
	# 	print("点阵显示")
	# 	time.sleep(1)


	##超声波传感器
	# s3 = mlib.GetDevData(31,1)
	# dcm = (331.5 + 0.6 * 25) * (s3 * 0.000001) / 2 * 100; #由M 转CM *100
	# print("超声波返回数据：%.1fcm" % dcm)

##颜色传感器 1:red  2:green  3:blue
	# s3 = mlib.GetDevData(28,1)
	# print(s3)
	# time.sleep(2)
	# if(s3>0):
	# 	if(s3==1):
	# 		mlib.SetDevData(8,0x02,RgbValue1[0])
	# 	elif(s3==2):
	# 		mlib.SetDevData(8,0x02,RgbValue1[1])
	# 	elif(s3==3):
	# 		mlib.SetDevData(8,0x02,RgbValue1[2])
	# 	else:
	# 		mlib.SetDevData(8,0x02,RgbValue1[3])

	# ##声音传感器
	# s3 = mlib.GetDevData(9,3)
	# if(s3==1):
	# 	print("you")
	# else:
	# 	print("wu")

# # ##红外遥控
	mlib.SetDevData(6,0x01,fish1)
	s1 = mlib.ReadDevData(6,0x01)
	time.sleep(0.5)
	print(s1)
	# mlib.SetDevData(8,0x02,RgbValue1[1])
	time.sleep(0.5)
##巡线传感器 ir2: s3   ir1: s4  黑色返回0 非黑色返回1 
	# s3 = mlib.GetDevData(15,0x03)
	# s4 = mlib.GetDevData(15,0x07)
	# if(s3==1 and s4==1):
	# 	print("11")
	# if(s3==0 and s4==0):
	# 	print("00")
	# if(s3==1 and s4==0):
	# 	print("10")
	# if(s3==0 and s4==1):
	# 	print("01")

###rgb彩灯传感器 ir2: s3   ir1: s4
	# mlib.SetDevData(8,0x02,RgbValue1[0])
	# time.sleep(0.5)
	# mlib.SetDevData(8,0x02,RgbValue1[1])
	# time.sleep(0.5)
	# mlib.SetDevData(8,0x02,RgbValue1[2])
	# time.sleep(0.5)
	# mlib.SetDevData(8,0x02,RgbValue1[3])
	# time.sleep(0.5)
